package com.intech.android.demo.cms.beans;

import com.intech.android.demo.cms.common.Constants;
import com.intech.android.demo.cms.common.FacesHelper;
import com.intech.android.demo.cms.common.Util;
import com.intech.android.demo.cms.decorators.BannerDecorator;

import java.util.ArrayList;
import java.util.List;

public class BannerBean
{
    private String bannerId;
    private String bannerName;
    private String advertiserName;
    private String beginDate;
    private String endDate;
    private String currentBanner;
    private List<BannerDecorator> bannerDecorators;
    private List<String> bannerActivity;

    public BannerBean()
    {
        currentBanner = "inactive";
        bannerActivity = new ArrayList<String>();
        bannerActivity.add("active");
        bannerActivity.add("inactive");
    }

    public String editBanner()
    {
        Integer banner_ID = FacesHelper.getParameterAsInteger("edit_banner");
        if (banner_ID == null)
        {
            return Constants.Navigation.BANNERS_LINK;
        }
        fillAddBannerForm(banner_ID);

        return Constants.Navigation.ADD_BANNER_LINK;
    }

    public String addBanner()
    {
        bannerId = "54";
        bannerName = null;
        advertiserName = null;
        beginDate = null;
        endDate = null;
        return Constants.Navigation.ADD_BANNER_LINK;
    }

    public String toBanners()
    {
        return Constants.Navigation.BANNERS_LINK;
    }

    private void fillAddBannerForm(Integer bannerNumber)
    {
        BannerDecorator currentDecorator = new BannerDecorator();
        for (BannerDecorator bannerDecorator : bannerDecorators)
        {
            if (Integer.parseInt(bannerDecorator.getBanner_ID()) == bannerNumber)
            {
                currentDecorator = bannerDecorator;
            }
        }
        bannerId = currentDecorator.getBanner_ID();
        bannerName = currentDecorator.getName();
        advertiserName = currentDecorator.getAdvertiser();
        beginDate = currentDecorator.getBeginDate();
        endDate = currentDecorator.getEndDate();
    }

    private void fillBannerListTempValues()
    {
        bannerDecorators = new ArrayList<BannerDecorator>();
        bannerDecorators.add(new BannerDecorator("1", "Mers", "Company 1", "Statistic", "06.11.2011", "06.02.2012", "active"));
        bannerDecorators.add(new BannerDecorator("2", "Vase", "Company 2", "Base menu", "07.12.2011", "07.01.2012", "active"));
        bannerDecorators.add(new BannerDecorator("3", "Hospital", "Company 3", "Capital", "23.08.2011", "23.11.2011", "inactive"));
        bannerDecorators.add(new BannerDecorator("4", "Earrings", "Company 4", "Choosing ad type", "23.10.2011", "23.12.2011", "active"));
    }

    public List<BannerDecorator> getBannerDecorators()
    {
        if (Util.isEmpty(bannerDecorators))
        {
            fillBannerListTempValues();
        }
        return bannerDecorators;
    }


    public void setBannerDecorators(List<BannerDecorator> bannerDecorators)
    {
        this.bannerDecorators = bannerDecorators;
    }

    public String getCurrentBanner()
    {
        return currentBanner;
    }

    public void setCurrentBanner(String currentBanner)
    {
        this.currentBanner = currentBanner;
    }

    public List<String> getBannerActivity()
    {
        return bannerActivity;
    }

    public void setBannerActivity(List<String> bannerActivity)
    {
        this.bannerActivity = bannerActivity;
    }

    public String getAdvertiserName()
    {
        return advertiserName;
    }

    public void setAdvertiserName(String advertiserName)
    {
        this.advertiserName = advertiserName;
    }

    public String getBannerName()
    {
        return bannerName;
    }

    public void setBannerName(String bannerName)
    {
        this.bannerName = bannerName;
    }

    public String getBannerId()
    {
        return bannerId;
    }

    public void setBannerId(String bannerId)
    {
        this.bannerId = bannerId;
    }

    public String getEndDate()
    {
        return endDate;
    }

    public void setEndDate(String endDate)
    {
        this.endDate = endDate;
    }

    public String getBeginDate()
    {

        return beginDate;
    }

    public void setBeginDate(String beginDate)
    {
        this.beginDate = beginDate;
    }
}
